package com.zhengshang.web.controller.app;

import com.zhengshang.api.domain.AppOilcard;
import com.zhengshang.api.service.IAppOilcardService;
import com.zhengshang.common.annotation.Log;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.core.page.TableDataInfo;
import com.zhengshang.common.enums.BusinessType;
import com.zhengshang.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户加油卡Controller
 * 
 * @author zhengshang
 * @date 2022-04-10
 */
@RestController
@RequestMapping("/app/oilcard")
public class AppOilcardController extends BaseController
{
    @Autowired
    private IAppOilcardService appOilcardService;

    /**
     * 查询用户加油卡列表
     */
    @PreAuthorize("@ss.hasPermi('app:oilcard:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppOilcard appOilcard)
    {
        startPage();
        List<AppOilcard> list = appOilcardService.selectAppOilcardList(appOilcard);
        return getDataTable(list);
    }

    /**
     * 导出用户加油卡列表
     */
    @PreAuthorize("@ss.hasPermi('app:oilcard:export')")
    @Log(title = "用户加油卡", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppOilcard appOilcard)
    {
        List<AppOilcard> list = appOilcardService.selectAppOilcardList(appOilcard);
        ExcelUtil<AppOilcard> util = new ExcelUtil<AppOilcard>(AppOilcard.class);
        return util.exportExcel(list, "oilcard");
    }

    /**
     * 获取用户加油卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:oilcard:query')")
    @GetMapping(value = "/{oilcardId}")
    public AjaxResult getInfo(@PathVariable("oilcardId") Long oilcardId)
    {
        return AjaxResult.success(appOilcardService.selectAppOilcardById(oilcardId));
    }

    /**
     * 新增用户加油卡
     */
    @PreAuthorize("@ss.hasPermi('app:oilcard:add')")
    @Log(title = "用户加油卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppOilcard appOilcard)
    {
        return toAjax(appOilcardService.insertAppOilcard(appOilcard));
    }

    /**
     * 修改用户加油卡
     */
    @PreAuthorize("@ss.hasPermi('app:oilcard:edit')")
    @Log(title = "用户加油卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppOilcard appOilcard)
    {
        return toAjax(appOilcardService.updateAppOilcard(appOilcard));
    }

    /**
     * 删除用户加油卡
     */
    @PreAuthorize("@ss.hasPermi('app:oilcard:remove')")
    @Log(title = "用户加油卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{oilcardIds}")
    public AjaxResult remove(@PathVariable Long[] oilcardIds)
    {
        return toAjax(appOilcardService.deleteAppOilcardByIds(oilcardIds));
    }
}
